package com.cj.service.impl;

import com.cj.dao.ClassStudentListDao;
import com.cj.po.DClass;
import com.cj.po.Dormclean;
import com.cj.po.PageInfo;
import com.cj.po.Student;
import com.cj.service.ClassStudentListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("classStudentListService")
@Transactional
public class ClassStudentListImpl implements ClassStudentListService {
    @Autowired
    private ClassStudentListDao classStudentListDao;

    @Override
    public PageInfo<DClass> findPageInfo(String c_classname, Integer c_classid, Integer pageIndex, Integer pageSize) {
        PageInfo<DClass> di = new PageInfo<DClass>();
        di.setPageIndex(pageIndex);
        di.setPageSize(pageSize);

        //获取总条数
        Integer totalCount = classStudentListDao.totalCount(c_classname,c_classid);
        if (totalCount>0){
            di.setTotalCount(totalCount);
            //每一页显示班级学生信息数
            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
            List<DClass> classStudentList = classStudentListDao.getClassStudentList(c_classname, c_classid,
                    (di.getPageIndex()-1)*di.getPageSize(),di.getPageSize());
            di.setList(classStudentList);
        }
        return di;
    }
}
